package com.ocean.admin.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ocean.admin.entity.SysUserPost;
import com.ocean.admin.mapper.SysUserPostMapper;
import com.ocean.admin.service.ISysUserPostService;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 用户与岗位关联表 服务实现类
 * </p>
 *
 * @author zhang
 * @since 2022-08-16
 */
@Service
public class SysUserPostServiceImpl extends ServiceImpl<SysUserPostMapper, SysUserPost> implements ISysUserPostService {

    /**
     * 保存岗位和用户关系
     *
     * @param postIds 岗位ID组
     * @param userId  用户ID
     */
    @Override
    public void saveUserPost(Long[] postIds, Long userId) {
        if (postIds != null && postIds.length != 0) {
            List<SysUserPost> collect = Arrays.stream(postIds).map(res -> {
                SysUserPost up = new SysUserPost();
                up.setUserId(userId);
                up.setPostId(res);
                return up;
            }).collect(Collectors.toList());
            this.saveBatch(collect);
        }
    }
}
